<header class="layout head padding-small">
    <a href="javascript:back(true);" class="hBack float-left"></a>
    <h4 class="hTxt float-left text-center text-white">购物车</h4>
    <a href="javascript:;" id="btnJdkey" class="hHlep float-right"></a>
</header>

<!--有内容S-->
<?php if(!empty($output['brand_cart_group']) && is_array($output['brand_cart_group'])){?>
    <div class="bg-white  margin padding radius-big cart-list padding-bottom clearfix">
        <a url="index.php?act=cart" onClick="pclicked(this);">
            <span class="<?php if(empty($_GET['brand_id'])){?>cart_title_curr<?php }?>">进货车</span>
        </a>
        <?php foreach ($output['brand_cart_group'] as $bcg){?>
            <a url="index.php?act=cart&brand_id=<?php echo $bcg['brand_id'];?>" onClick="pclicked(this);">
        <span class="<?php if($_GET['brand_id'] == $bcg['brand_id']){?>cart_title_curr<?php }?>">
            <?php echo $bcg['brand_name'];?>进货车
        </span>
            </a>
        <?php }?>
    </div>
<?php }?>

<!--进货车S-->
<?php if (!empty($output['cart_goods_list']) && is_array($output['cart_goods_list'])) { ?>
<?php foreach ($output['cart_goods_list'] as $cart_store_id => $cart_store_goods_list) { ?>
<div class="bg-white  margin padding radius-big cart-list padding-bottom clearfix" id="storemodule_<?php echo $cart_store_id; ?>">
    <!--商城S-->
    <div class="sale-off clearfix padding-bottom">
        <a href="javascript:;" class="saleCheckBtn checkbox float-left border border-gray" data-store_id="<?php echo $cart_store_id;?>"></a>
        <i class="sale-icon float-left margin-left"></i>
        <?php if ($cart_store_id == JKY_STORE_ID) { ?><a url="index.php?act=activity" class="margin-left" onClick="pclicked(this);"><?php echo $output['cart_store_list'][$cart_store_id]['store_name']; ?></a>
        <?php }else if($cart_store_id == OFFICIAL_STORE_ID) { ?>
        <a url="index.php?act=official_shop" class="margin-left" onClick="pclicked(this);"><?php echo $output['cart_store_list'][$cart_store_id]['store_name']; ?></a>
        <?php }else{ ?>
            <a url="<?php echo ncUrl(array('act' => 'show_store', 'id' => $cart_store_id), 'store', $output['cart_store_list'][$cart_store_id]['store_domain']); ?>" class="margin-left" onClick="pclicked(this);"><?php echo $output['cart_store_list'][$cart_store_id]['store_name']; ?></a>
        <?php } ?>
    </div>
    <!--商城E-->

    <!--满送优惠信息S-->
    <?php if ($output['cart_mansong_id_list'][$cart_store_id]) { ?>
    <p class="discount-txt text-small text-red" >
        <?php if($output['cart_mansong_list'][$cart_store_id]){?>
        <?php foreach($output['cart_mansong_list'][$cart_store_id] as $strrule){
            echo $strrule,'<br />';
          };?>
      </p>
    <?php }} ?>

    <!--商品S-->
    <ul class="sale-tab border radius padding-small" id="store_data_list_<?php echo $cart_store_id?>">
            <?php foreach ( $cart_store_goods_list as $cart_id => $cart_store_goods_row) { ?>
        <li class="sale-tab-list" id="cart_item_<?php echo $cart_store_goods_row['spec_id']; ?>">
        <div class="clearfix">

                <a url="<?php echo ncUrl(array('act' => 'goods', 'goods_id' => $cart_store_goods_row['goods_id']), 'goods'); ?>" class="goods-img float-left margin-small-right" onClick="pclicked(this);">
                    <img alt="<?php echo $cart_store_goods_row['goods_name']; ?>" src="<?php echo thumb($cart_store_goods_row, 'small'); ?>" onload="javascript:DrawImage(this,60,60);" onerror="this.src='<?php echo TEMPLATES_PATH;?>/images/touch2013/no_100_100.jpg'">
                </a>
                <a url="<?php echo ncUrl(array('act' => 'goods', 'goods_id' => $cart_store_goods_row['goods_id']), 'goods'); ?>" class="goods-name text-small" onClick="pclicked(this);"><?php echo $cart_store_goods_row['goods_name']; ?></a>
            </div>
            <div class="padding-top padding-left clearfix">
                <span class="goods-price text-red float-left padding-right">￥<span><?php echo $cart_store_goods_row['spec_goods_price']; ?></span>&nbsp;&nbsp;x</span>
                <div class="float-left radius text-center border border-ef7f7e goods-num">
        <?php if ($cart_store_id != JKY_STORE_ID){ ?>
                    <span class=" bg-ef7f7e inlineBlock text-white numDel" onclick="change_num(<?php echo $cart_store_goods_row['store_id'];?>,<?php echo $cart_store_goods_row['spec_id']; ?>,'minus')">-</span>
                    <span class="numWrite inlineBlock" ><input type="text" onblur="change_num(<?php echo $cart_store_goods_row['store_id'];?>,<?php echo $cart_store_goods_row['spec_id']; ?>)" value="<?php echo $cart_store_goods_row['goods_num']; ?>" class=" text-center border-none" id="goods_spec_id_<?php echo $cart_store_goods_row['spec_id']; ?>"></span>
                    <span class="text-white inlineBlock bg-red numAdd" onclick="change_num(<?php echo $cart_store_goods_row['store_id'];?>,<?php echo $cart_store_goods_row['spec_id']; ?>,'plus')">+</span>
                <?php } else { ?>
            <span class="numWrite inlineBlock" ><input type="text" disabled value="<?php echo $cart_store_goods_row['goods_num']; ?>" class=" text-center border-none" "></span>
                <?php }?>
                </div><br><br>
                <span><?php echo $cart_store_goods_row['cart_spec_info']; ?></span>
                <span class="icon-trash-o float-right text-gray text-big goods-del" onclick="drop_cart_item(<?php echo $cart_store_id; ?>, <?php echo $cart_store_goods_row['spec_id']; ?>)"></span>
            </div>
        </li>
            <?php }?>
    </ul>
    <!--商品E-->
    <div class="padding-top">
        <a url="index.php?act=order&op=show_cart_order&store_id[]=<?php echo $cart_store_id; ?><?php if($_REQUEST['brand_id']){echo '&brand_id='.$_REQUEST['brand_id'];}?>" class="float-right bg-red radius text-white padding-small" onClick="pclicked(this);">确定订单</a>
        <div class="sale-price text-small">总价（不含运费）：<span id="amount_<?php echo $cart_store_id?>" class="text-red text-big">&yen;<?php echo ncPriceFormat($output['cart_store_price_list'][$cart_store_id]); ?></span></div>
    </div>
</div>
<!--进货车E-->
    <?php }?>
<!--合并订单S-->
<div class="sale-add bg-white radius-big clearfix margin padding">
    <a href="javascript:;" class=" float-left height-big" id="checkAll"><span class="checkbox border border-gray inlineBlock margin-right"></span>全选</a>
    <a href="javascript:;" class="float-right bg-red radius text-white padding-small" id="hbdd">合并支付</a>
</div>
<!--合并订单E-->
</form>

<!--有内容E-->
<?php }else{?>
<!--无内容S-->
<div class="noTxt text-center text-gray padding-large">
    <i class="icon-meh-o"></i>
    <p>您的进货车还没有商品哦，<br><a url="index.php" class="text-ef7f7e" onClick="pclicked(this);">随便逛逛</a>可能会遇到喜欢的商品。</p>
</div>
<!--无内容E-->
<?php }?>
<script>
    //商品数量 +/-
    /*
     *   商品数量 +/-、数量文本框失去焦点事件
     *   change_type：改变类型为 + 或 -
     * */
    function change_num(store_id,spec_id,change_type){
        var brand_id = 0;
        <?php if(intval($_GET['brand_id']) > 0 ){ ?>
            brand_id = <?php echo intval($_GET['brand_id']);?>;
        <?php } ?>
        var amount_span = $('#amount_' + store_id);
        var $goodsNumInput = $('input[id=goods_spec_id_'+spec_id+"]"),
            goodsNum = $goodsNumInput.val(),//原来数量
            //变化后的数量
            goodsNumNew;
        if(change_type == 'plus'){
            goodsNumNew =  parseInt(goodsNum)+1;
            $goodsNumInput.val(goodsNumNew);
        }else if(change_type == 'minus'){
            goodsNumNew = parseInt(goodsNum)-1;
            if(goodsNumNew<=0){
                goodsNumNew=1;
            }
            $goodsNumInput.val(goodsNumNew);
        }else {
            goodsNumNew = goodsNum;
        }
        //发送ajax改变进货车商品数量和总价
        $.getJSON('index.php?act=cart&op=update&spec_id=' + spec_id + '&quantity=' + goodsNumNew + '&brand_id=' + brand_id, function(result){
            if(result.done){
                //更新成功
                amount_span.html(result.amount);
            }
            else{
                alert(result.msg);
                $goodsNumInput.val(goodsNum);
            }
        });

    }

    function drop_cart_item(store_id, spec_id){
        if(!confirm('确定删除此商品吗？'))return;
        var li_good = $('#cart_item_' + spec_id);
        var amount_span = $('#amount_' + store_id);
        $.getJSON('index.php?act=cart&op=drop&d=m&specid=' + spec_id + '&storeid=' + store_id, function(result){
            if(result.done){
                //删除成功
                if(result.quantity == 0){//判断进货车是否为空
                    window.location.reload();    //刷新
                }else{
                        if(result.store_quantity == 0){
                            $("#storemodule_"+store_id).remove();
                        }
                        //如果是九块邮商城
                        if(store_id==<?php echo JKY_STORE_ID?>){
                            $('#store_data_list_<?php echo JKY_STORE_ID?>').html(result.htmldata);
                        }else{
                            li_good.remove();        //移除
                        }
                        amount_span.html(result.store_amount);  //刷新总费用
                }
            }else{
                alert(result.msg);
            }
        });
    }
</script>
<script>
    $(function(){
        /*合并订单事件*/
        $('#hbdd').click(function(){
            var url = 'index.php?act=order&op=show_cart_order';
            var store_id = '';
            $(".checkbox").each(function () {
                if ($(this).hasClass('checked') && $(this).data('store_id') != 'undefined' && $(this).data('store_id') != null) {
                    store_id += '&store_id[]=' + $(this).data('store_id');
                }
            });
            if(store_id==''){alert('请选商城');return;}
             pclicked(url + store_id);;
        });

        //如果商城数量有多个，则出现全选按扭。
       $('.sale-add').hide();
        if($('div[id^=storemodule_]').length > 1){
            $('.sale-add').show();
        }

        //进货车选择
        //全选
        $('#checkAll').click(function(){
            var $allCheck = $(this).parents('.sale-add').siblings('.cart-list').find('.checkbox'),
                $checkAll = $(this).find('.checkbox');
            if($checkAll.hasClass('checked')== false){
                //本身
                $checkAll.addClass('checked');
                //全部
                $allCheck.addClass('checked');
            }else if($checkAll.hasClass('checked') == true){
                $checkAll.removeClass('checked');
                //$saleCheck.removeClass('checked');
                $allCheck.removeClass('checked');
            }
        })
        //选择商城
        $('.saleCheckBtn').click(function(){
            var $allCheck = $('#checkAll').find('.checkbox'),
                $goodsCheck = $(this).parent('.sale-off').siblings().find('.checkbox');
            if($(this).hasClass('checked')== false){
                //本身
                $(this).addClass('checked');
                //选择商城
                $goodsCheck.addClass('checked');
                //全部
                if($('.sale-off .checked').length == $('.saleCheckBtn').length){
                    $allCheck.addClass('checked');
                }
            }else if($(this).hasClass('checked') == true){
                $(this).removeClass('checked');
                $goodsCheck.removeClass('checked');
                $allCheck.removeClass('checked');
            }
        })
    })

</script>